﻿var isGetContentSucc = false;

$(document).ready(function () {

    $(".txtBrows").blur(function () {

        //        var offset = $(this).offset();
        //        var xVal = offset.left;
        //        var yVal = offset.top;
        //        var sUrl = $(this).val();
        //        ShowHideLoading(true, xVal, yVal + 30);
        //        var idCurr = $(this).attr('id');
        //        $.ajax({
        //            url: "Clustering.aspx/GetContentFromUrl",
        //            type: "POST",
        //            data: JSON.stringify({ 'sUrl': sUrl }),
        //            dataType: "json",
        //            contentType: "application/json; charset=utf-8",
        //            success: function (data) { GetContentSucc(data, idCurr); },
        //            error: function () { }
        //        });
        //if (isGetContentSucc === false)
            GetContent(this);

    });

    $(".txtBrows").bind('paste', function () {
       // GetContent(this);
    });

});

function GetContent(txt) {
    var offset = $(txt).offset();
    var xVal = offset.left;
    var yVal = offset.top;
    var sUrl = $(txt).val();
    if (sUrl !== 'http://') {
        ShowHideLoading(true, xVal, yVal + 30);
        var idCurr = $(txt).attr('id');
        if (sUrl !== '') {
            $.ajax({
                url: "Clustering.aspx/GetContentFromUrl",
                type: "POST",
                data: JSON.stringify({ 'sUrl': sUrl }),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) { GetContentSucc(data, idCurr); },
                error: function () { }
            });
        }
    }
}

function ShowHideLoading(bCheck,xVal,yVal) {
    if (bCheck === true) {
        $('.loading').show();
        $('.loading').css({ top: yVal, left: xVal });
    }
    else
        $('.loading').hide();

}

function GetContentSucc(data, a) {
    var textarea = $("#" + a).next().next();
    $(textarea).val(data.d);
    ShowHideLoading(false, 1, 1);
    isGetContentSucc = true;
}